<template>
  <div class="app-container">
    <div class="app-form">
      <ele-form
        v-model="formData"
        v-bind="formConfig"
        :request-fn="handleRequest"
        @request-success="handleRequestSuccess"
      />
    </div>
  </div>
</template>

<script>
import {
  serverCreate
} from '@projectName/views/diandi_place/api/place/server'
export default {
  data() {
    return {
      formData: {
        status: 1
      },
      formConfig: {
        formDesc: {
          bloc_id: {
            type: 'cascader-bloc',
            label: '选择楼栋'
          },
          displayorder: {
            type: 'number',
            label: '排序'
          },
          title: {
            type: 'input',
            label: '服务名称'
          },
          desc: {
            type: 'input',
            label: '服务说明'
          },
          thumb: {
            type: 'image-uploader',
            label: '图标'
          }
        },
        order: []
      }
    }
  },
  methods: {
    handleRequest(data) {
      serverCreate(data).then((response) => {
        if (response.code === 200) {
          this.$message.success(response.message)
          this.closePage()
        } else {
          this.$message.error(response.message)
        }
      })
      return Promise.resolve()
    },
    handleRequestSuccess() {},
    closePage() {
      this.$store.dispatch('app/closePage', {
        vm: this,
        fromName: this.$route.name,
        toName: 'diandi-place-place-server-index',
        params: {}
      })
    }
  }
}
</script>
